Skip to content

feat(common): add support for MCP configuration in component setup #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Jun 2, 2025

feat(common): 在组件设置中添加对 MCP 配置的支持

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Added support for a new tiny_mcp_config prop, allowing components to accept additional configuration options.
    • Components can now leverage external MCP configurations for enhanced customization.

Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

Support for a new prop, tiny_mcp_config, was added to the component props and types. A global configuration object and a registration function for MCP configuration and tool creation were introduced. Component setup logic now checks for relevant MCP config and invokes a global tool-creation function when conditions are met.

Changes

File(s) Change Summary
packages/vue-common/src/index.ts Added tiny_mcp_config prop and type; introduced globalMcpConfig, registerMcpConfig, and getComponentMcpConfig functions; updated component setup logic to handle MCP config and tool creation.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Component
    participant GlobalMcpConfig

    App->>GlobalMcpConfig: registerMcpConfig(mcpConfig, defineTool)
    App->>Component: Mount with props (may include tiny_mcp_config)
    Component->>GlobalMcpConfig: getComponentMcpConfig(componentName)
    alt MCP config and tiny_mcp_config and tool creator exist
        Component->>GlobalMcpConfig: Call defineTool(instance, tiny_mcp_config, componentMcpConfig)
    end
Loading

Poem

A new prop arrives, "tiny_mcp_config" in tow,
Global configs and tools now ready to flow.
Components check, then tools ignite,
With MCP magic, all feels right.
Hop, skip, setup anew—
Rabbits love fresh configs too! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue-common/src/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Jun 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccd4a69 and d4c162e.

📒 Files selected for processing (1)
  • packages/vue-common/src/index.ts (4 hunks)
🔇 Additional comments (4)
packages/vue-common/src/index.ts (4)

51-51: LGTM: Prop definition follows established patterns.

The addition of tiny_mcp_config as an Object type follows the existing naming convention and structure of other tiny_ props.


63-73: LGTM: Consistent type and runtime prop definitions with improved formatting.

The addition of tiny_mcp_config maintains consistency between the TypeScript type definition and the runtime props array. The formatting improvement with each prop on a separate line enhances readability.


183-187: 🛠️ Refactor suggestion

Add null safety to prevent potential runtime errors.

The function logic is sound, but it could throw runtime errors if mcpConfig is null or undefined when accessing the components property.

Apply this diff to add null safety:

 const getComponentMcpConfig = () => {
   const mcpConfig = globalMcpConfig.mcpConfig
   const componentName = getComponentName().replace($prefix, '')
-  return mcpConfig?.components?.[componentName]
+  return mcpConfig?.components?.[componentName] || null
 }

Likely an incorrect or invalid review comment.


189-192:

❓ Verification inconclusive

Consider potential SSR and multi-instance implications.

The global configuration pattern is appropriate for this use case. However, verify that this global state approach is compatible with SSR environments and multiple app instances.


🏁 Script executed:

#!/bin/bash
# Description: Check for SSR-related code or multi-instance patterns in the codebase
# Expected: Find patterns that might indicate SSR usage or multi-instance scenarios

echo "Searching for SSR-related patterns..."
rg -i "ssr|server.*side|nuxt|next\.js" --type ts --type js

echo -e "\nSearching for multi-app or instance patterns..."
rg -i "createApp|multiple.*app|app.*instance" --type ts --type js

Length of output: 20630


Verify SSR and multi-instance safety of globalMcpConfig

We didn’t find any direct issues in the vue-common implementation, but since the repo includes SSR hooks and multiple app-instance patterns, please ensure that your module-level globalMcpConfig won’t bleed state across server requests or separate Vue app instances.

Key spots to review:

  • internals/unplugin-virtual-template/src/nuxt.ts
    (Nuxt hooks imply SSR usage—module variables persist across requests)
  • Multiple createApp calls
    (e.g. examples/vue3/src/main.ts, packages/vue/src/… services append to document.body)

If needed, scope or reset globalMcpConfig per request/app initialized to avoid cross-instance crosstalk.

Comment on lines +307 to +310
const componentMcpConfig = getComponentMcpConfig()
if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) {
globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling to prevent component setup crashes.

The conditional logic is well-structured, but the MCP tool creation call could potentially throw errors that would crash the component setup process.

Apply this diff to add error handling:

   const componentMcpConfig = getComponentMcpConfig()
   if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) {
-    globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
+    try {
+      globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
+    } catch (error) {
+      console.warn('Failed to create MCP tools:', error)
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const componentMcpConfig = getComponentMcpConfig()
if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) {
globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
}
const componentMcpConfig = getComponentMcpConfig()
if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) {
try {
globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
} catch (error) {
console.warn('Failed to create MCP tools:', error)
}
}
🤖 Prompt for AI Agents
In packages/vue-common/src/index.ts around lines 307 to 310, the call to
globalMcpConfig.createMcpTools may throw errors that could crash the component
setup. Wrap this call in a try-catch block to catch any exceptions, log or
handle the error appropriately, and prevent the component from crashing during
setup.

Comment on lines +194 to +197
export const registerMcpConfig = (mcpConfig, defineTool) => {
globalMcpConfig.mcpConfig = mcpConfig
globalMcpConfig.createMcpTools = defineTool
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety with more specific type definitions.

The function works correctly but uses overly generic types that could lead to runtime errors and poor developer experience.

Consider adding more specific type definitions:

+interface McpConfig {
+  components?: Record<string, any>
+  [key: string]: any
+}
+
+interface McpToolCreator {
+  (vm: any, propConfig: any, componentConfig: any): void
+}
+
-export const registerMcpConfig = (mcpConfig, defineTool) => {
+export const registerMcpConfig = (mcpConfig: McpConfig, defineTool: McpToolCreator) => {
   globalMcpConfig.mcpConfig = mcpConfig
   globalMcpConfig.createMcpTools = defineTool
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const registerMcpConfig = (mcpConfig, defineTool) => {
globalMcpConfig.mcpConfig = mcpConfig
globalMcpConfig.createMcpTools = defineTool
}
interface McpConfig {
components?: Record<string, any>
[key: string]: any
}
interface McpToolCreator {
(vm: any, propConfig: any, componentConfig: any): void
}
export const registerMcpConfig = (mcpConfig: McpConfig, defineTool: McpToolCreator) => {
globalMcpConfig.mcpConfig = mcpConfig
globalMcpConfig.createMcpTools = defineTool
}
🤖 Prompt for AI Agents
In packages/vue-common/src/index.ts around lines 194 to 197, the function
registerMcpConfig uses overly generic parameter types which reduces type safety
and developer experience. Update the function signature to use more specific
type definitions for mcpConfig and defineTool based on their expected structures
or interfaces. This will help catch type errors at compile time and improve code
clarity.

@zzcr zzcr merged commit fb9222f into dev Jun 2, 2025
11 checks passed
@zzcr zzcr deleted the add-mcp-config-0602 branch June 2, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant